<template>
	<view class="content">

		<view class="block user-block">
			<image :src="imageUrl+'/mine/bg.jpg'" mode="widthFix" class='bg-img'></image>
			<view style="position: fixed;right: 5vh;top: 60rpx;width: auto;height: 5vh;" @click="saomasuy"><text
					style="color: azure;font-size: 55rpx;" class="iconfont icon-saoma"></text></view>

			<image :src="user?user.faceUrl:imageUrl+'/mine/default_face.png'" class="user-photo"></image>
			<view class="user-info">
				<view v-if="identity==2" class="user-name1">{{companyName}}</view>
				<view v-if="!user" @click="navigate('/page_other/login/select')" class="user-name">立即登录</view>
				<view v-else-if="identity==1" class="user-name">{{user.realName?user.realName:'游客'}}
					<text class="user-text"></text>
				</view>
				<view v-else-if="identity==2" class="user-name">{{user.realName?user.realName:'游客'}}<text
						style="font-weight: normal;" class="fs12 ml20"> {{user.comPosition?user.comPosition:''}}</text>
				</view>
				<view @click="navigate('/page_other/resume/index')" v-if="identity==1&&user" class="edit-resume"><text
						style="margin-right: 10rpx;" class="iconfont icon-bianjishuru"></text>编辑简历</view>
				<view @click="navigate('/page_other/enterprise/authorization/person-info')" v-if="identity==2&&user"
					class="edit-resume"><text style="margin-right: 10rpx;"
						class="iconfont icon-bianjishuru"></text>编辑个人信息</view>
			</view>
		</view>
		<view v-if="identity==1" class="block statistical-block">
			<view class="statistical-item" @click="navigate('/page_other/count_details/collect')">
				<view class="num">{{favouriteCount}}</view>
				<view class="name">收藏</view>
			</view>
			<view class="statistical-item" @click="navigate('/page_other/count_details/attention')">
				<view class="num">{{followCount}}</view>
				<view class="name">关注</view>
			</view>
			<view class="statistical-item" @click="navigate('/page_other/count_details/deliver')">
				<view class="num">{{deliveryCount}}</view>
				<view class="name">投递</view>
			</view>
			<view class="statistical-item" @click="navigate('/page_other/count_details/look')">
				<view class="num">{{lookMeCount}}</view>
				<view class="name">谁看过我</view>
			</view>
		</view>
		<view v-if="identity==2" class="block statistical-block">
			<view class="statistical-item" @click="navigate('/page_other/attention/attention?type=2&name=关注')">
				<view class="num">{{followCount}}</view>
				<view class="name">关注</view>
			</view>
			<view class="statistical-item" @click="navigate('/page_other/position/position_manage')">
				<view class="num">{{postCount}}</view>
				<view class="name">已发布</view>
			</view>
			<view class="statistical-item" @click="navigate('/page_other/accept/accept')">
				<view class="num">{{speakCount}}</view>
				<view class="name">收到的简历</view>
			</view>
			<view class="statistical-item" @click="navigate('/page_other/attention/attention?type=1&name=谁看过我')">
				<view class="num">{{lookMeCount}}</view>
				<view class="name">谁看过我</view>
			</view>
		</view>
		<view class="block menu-block">
			<view v-if="identity==1" class="menu-item" @click="navigate('/page_other/resume/intention')">
				<view style="color: #FE6335;font-size: 38rpx;" class="menu-icon iconfont icon-gerenziliao"></view>
				<view class="menu-name">求职意向</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<view v-if="identity==1" class="menu-item" @click="navigate('/page_other/resume/index')">
				<view style="color: #05a7fe;font-size: 38rpx;" class="menu-icon iconfont icon-register"></view>
				<view class="menu-name">我的简历</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<view v-if="identity==1" class="menu-item" @click="statusMenu">
				<view style="color: #FE6335;font-size: 38rpx;" class="menu-icon iconfont icon-xitongzhuangtai"></view>
				<view class="menu-name">求职状态<span style="float: right;color:darkgray">{{user.jobStatusText}}</span>
				</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<view hover-class="none" v-if="identity==2" class="menu-item" @click="navigate('/page_other/company/form')">
				<view style="color: #FE6335;font-size: 38rpx;" class="menu-icon iconfont icon-qiye"></view>
				<view class="menu-name">我的公司</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<view hover-class="none"
				v-if="user.authenticationStatus == 3||user.authenticationStatus == 9||user.authenticationStatus == 4"
				class="menu-item" @click="navigate('/page_other/enterprise/authorization/business')">
				<view style="color: #FE6335;font-size: 38rpx;" class="menu-icon iconfont icon-jianli"></view>

				<view class="menu-name">我的资料<span style="float: right;color:darkgray"><span
							v-if="user.authenticationStatus != 9" style="color:red;">{{user.rregisterStateText}}</span>
						<span v-if="user.authenticationStatus == 9"
							style="color:chartreuse;">{{user.rregisterStateText}}</span>
					</span></view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<!-- 			<view v-if="identity==1" @click="navigate('/page_other/for_privacy/index')" class="menu-item">
				<view style="color: #3CC40D;font-size: 38rpx" class="menu-icon iconfont icon-yinsi"></view>
				<view class="menu-name">求职隐私</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view> -->
			<view v-if="identity==2" class="menu-item" @click="navigate('/page_other/position/position_manage')">
				<view style="color: #3CC40D;font-size: 38rpx" class="menu-icon iconfont icon-zhiwei"></view>
				<view class="menu-name">职位管理</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<view v-if="identity==2" class="menu-item" @click="navigate('/page_other/accept/accept')">
				<image :src="imageUrl+'/mine/resume.png'" mode="widthFix" class="menu-icon iconfont"
					style="width:50rpx;margin-right:20rpx;"></image>
				<view class="menu-name">收到的简历</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<view v-if="identity==2" class="menu-item" @click="navigate('/page_other/my_jobfair/my_jobfair')">
				<view style="color: #05a7fe;font-size: 38rpx;" class="menu-icon iconfont icon-xingye"></view>
				<view class="menu-name">我的招聘会</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<view class="menu-item" @click="navigate('/page_other/feedback/feedback')">
				<view style="color: #05a7fe;font-size: 38rpx;" class="menu-icon iconfont icon-jubao"></view>
				<view class="menu-name">意见反馈</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<view @click="identityMenu()" v-if="identity==1" class="menu-item">
				<view style="color: #8B4BFD;" class="menu-icon iconfont icon-daijiuye"></view>
				<view class="menu-name">我要招人</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<view @click="identityMenu()" v-if="identity==2" class="menu-item">
				<view style="color: #8B4BFD;" class="menu-icon iconfont icon-daijiuye"></view>
				<view class="menu-name">我要求职</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
			<view @click="navigate('/page_other/instructions/add_crowd')" class="menu-item">
				<view style="color: #00aa00;" class="menu-icon iconfont icon-weixin"></view>
				<view class="menu-name">技术支持</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
		</view>
		<view class="block menu-block" v-if="user">
			<view @click="identityMenu()" class="menu-item">
				<view style="color: #7F94FA;font-size: 38rpx;" class="menu-icon iconfont icon-tuichudenglu"></view>
				<view class="menu-name">退出登录</view>
				<view class="arrow iconfont icon-gengduo1"></view>
			</view>
		</view>
		<view @click="callPhone('0937-2880255')" style="text-align: center;font-size: 14px;">
			技术支持电话：0937-2880255
		</view>

	</view>
</template>

<script>
	import {
		submitUserStatus,
		getLookMeCountApi
	} from '@/api/customer.js';
	import {
		doScanSuccessApi
	} from '@/api/user.js';
	import {
		mapGetters
	} from 'vuex';
	import {
		isLogin
	} from '@/util/user.js'
	import {
		getComRecruiters
	} from '@/api/company.js'
	import {
		getUser
	} from '@/api/user.js'

	import {
		getIntentionList as getIntentionListApi,

	} from '@/api/resume.js';
	import {
		doOperationRecordsApi
	} from '@/api/job_hunting.js'
	export default {
		data() {
			return {
				imageUrl: '',
				itemList: ['离职-随时到岗', '在职-月内到岗', '在职-考虑机会', '在职-暂不考虑'],
				jobStatus: '',
				followCount: 0,
				favouriteCount: 0,
				deliveryCount: 0,
				lookMeCount: 0,
				postCount: 0,
				speakCount: 0,
				companyName: ''
			}
		},
		computed: {
			...mapGetters(['identity', 'user']),
			user() {
				return this.$store.getters.user
			}
		},
		onShow() {
			if (isLogin() && (this.identity == 1 || (this.identity == 2 && (this.user.authenticationStatus == 3 || this
					.user.authenticationStatus == 9)))) {
				this.followListApi();
				this.$store.dispatch('user/getUser')
			}
			if (isLogin() && this.identity == 2) {
				this.getDetail()
			}
			if (isLogin() && this.identity == 1) {
				this.getIntention()
			}
			if (!isLogin()) {
				this.companyName = '';
			}
		},
		onLoad() {
			this.imageUrl = this.globalConfig.imageUrl;
		},
		methods: {
			callPhone(mobile) {
				if (this.isLogin()) {
					let para = {
						cancelText: '我再想想',
						success: (confirm) => {
							if (confirm.confirm) {
								uni.makePhoneCall({
									phoneNumber: mobile,
									success() {
										console.log('拨打成功了');
									},
									fail() {
										console.log('拨打失败了');
									}
								})
								this.getCount(3)
							}
						}
					}
					para.title = '确认拨打';
					para.content = '技术支持'
					para.confirmText = '拨打';
					uni.showModal(para);
				}
			},
			getCount(type) {
				uni.showLoading({
					title: '加载中'
				})
				doOperationRecordsApi({
					type: type,
				}).then((res) => {
					console.log(res)
				}).catch(() => {
					console.log(res)
				})
			},
			isLogin() {
				if (!this.user) {
					uni.showModal({
						title: '提示',
						content: '需要先登录！',
						cancelText: '先逛逛',
						confirmText: '去登录',
						success(res) {
							if (res.confirm) {
								uni.switchTab({
									url: '/pages/mine/index'
								})
							} else {

							}
						}
					})
					return false;
				} else {
					return true;
				}
			},
			navigate(url) {

				if (this.user) {
					if (url == '/page_other/company/form' || url == '/page_other/position/position_manage') {
						getUser({
							type: 2
						}).then((res) => {
							const com = res

							if (com.authenticationStatus == 3) {
								this.showToast('等待审核中，暂不可操作', () => {

									return;
								});

							} else if (com.authenticationStatus == 4) {
								this.showToast('审核不通过，请重新上传', () => {

									return;
								});

							} else {
								uni.navigateTo({
									url
								})
							}
						})
					} else {

						uni.navigateTo({
							url
						})
					}
				} else {
					uni.navigateTo({
						url,
						fail(e) {
							console.log(e)
						}
					})
				}


			},
			getDetail() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getComRecruiters({}).then((res) => {
					this.companyName = res.com.comShortName;
				})
			},
			getIntention() {
				getIntentionListApi({
					id: 0
				}).then((res) => {
					if (!res) {
						uni.showModal({
							title: '提示',
							content: `为了更好的为您精准的匹配岗位，请您填写您的求职意向`,
							confirmColor: '#FF7626',
							success: (res) => {
								if (res.confirm) {
									uni.reLaunch({
										url: '/page_other/resume/career_intention'
									})
								}
							}
						})
					}

				})
			},
			followListApi() {
				getLookMeCountApi({
					type: this.identity
				}).then((res) => {
					this.followCount = res.followCount;
					this.favouriteCount = res.favouriteCount;
					this.deliveryCount = res.deliveryCount;
					this.lookMeCount = res.lookMeCount;
					this.postCount = res.jobPublishCount;
					this.speakCount = res.deliveryCount;
				})
			},
			statusMenu() {
				let _this = this;
				uni.showActionSheet({
					itemList: this.itemList,
					success(e) {
						let index = e.tapIndex + 1;
						submitUserStatus({
							jobStatus: index
						}).then((res) => {
							_this.$store.dispatch('user/getUser');
							uni.showToast({
								title: '修改成功',
								icon: 'success'
							});
						}).catch((res) => {
							console.log(res)
						})

					}
				})
			},
			identityMenu() {
				uni.showModal({
					title: '提示',
					content: `确定要退出重新登录吗？`,
					confirmColor: '#FF7626',
					success: (res) => {
						if (res.confirm) {
							this.$store.commit('user/SET_TOKEN', null)
							this.$store.commit('user/SET_USER', null)
							this.$store.commit('user/SET_IDENTITY', null)
							this.companyName = '';
							uni.$TUIKit && uni.$TUIKit.logout()
							uni.reLaunch({
								url: '/pages/index/index'
							})
						}
					}
				})
			},
			saomasuy() {
				var e = this;
				wx.scanCode({ //允许从相机与相册扫码，调起客户端扫码界面进行扫码
					success: function(a) {
						// scanType	string	所扫码的类型
						if (a.scanType == 'WX_CODE') {
							var t = a.path.split("="); //当所扫的码为当前小程序二维码时，会返回此字段，内容为二维码携带的 path
							var scene = t[1]
							doScanSuccessApi({
								scene: scene
							}).then((res) => {

								uni.navigateTo({
									url: "/" + a.path
								})
							})

						}
						wx.showLoading({
							title: "正在查询..."
						});
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #FAFAFA;
	}

	.content {
		width: 100%;
		padding: 30rpx;

		.block {
			width: 100%;
			border-radius: 20rpx;
			//box-shadow: 0 0 10px 0 #efefef;
			margin-bottom: 30rpx;
		}

		.user-block {
			height: 320rpx;
			//background: linear-gradient(#FC0E3F, #FEAFBD);
			padding: 30rpx;
			display: flex;
			flex-direction: row;
			align-items: center;

			.bg-img {
				width: calc(100% - 60rpx);
				position: absolute;
				left: 30rpx;
				right: 30rpx;
				border-radius: 16rpx;
			}

			.user-photo {
				width: 130rpx;
				height: 130rpx;
				background: #efefef;
				border-radius: 50%;
				margin-right: 20rpx;
				position: relative;
			}

			.user-info {
				width: calc(100% - 150rpx);
				color: #fff;
				position: relative;

				.user-name {
					font-weight: bold;

					.user-text {
						font-size: 24rpx;
						margin-left: 10%;
						color: #c6c6c6;
					}
				}

				.user-name1 {
					font-weight: bold;
					margin-bottom: 10rpx;

					.user-text {
						font-size: 24rpx;
						margin-left: 10%;
						color: #c6c6c6;
					}
				}

				.edit-resume {
					margin-top: 20rpx;
					font-size: 28rpx;
				}
			}
		}

		.statistical-block {
			background: #fff;
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: 45rpx 0;

			.statistical-item {
				width: 25%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				.num {
					font-weight: bold;
					font-size: 36rpx;
				}

				.name {
					font-size: 26rpx;
					color: #313131;
					margin-top: 15rpx;
				}
			}
		}

		.menu-block {
			background: #fff;

			.menu-item {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				height: 100rpx;
				padding: 0 40rpx;

				>view {
					border-bottom: 1px solid #efefef;
					height: 100%;
				}

				.menu-icon,
				.arrow {
					width: 70rpx;
					height: 100rpx;
					line-height: 100rpx;
				}

				.menu-icon {
					text-align: left;
				}

				.arrow {
					color: #c6c6c6;
					text-align: right;
				}

				.menu-name {
					width: calc(100% - 140rpx);
					font-size: 28rpx;
					line-height: 100rpx;
				}
			}

			.menu-item:last-child {
				border: none;
			}
		}
	}
</style>